#ifndef YB_LOG_BROWSE_H
#define YB_LOG_BROWSE_H

#include <QWidget>

#include "pub_pop_delay.h"

#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkInterface>
#include <QNetworkRequest>
#include <QJsonObject>
#include <QJsonArray>
#include <QSqlQuery>
#include <QMap>
#include <QSqlQueryModel>
#include <QTreeWidgetItem>

#include <QStyledItemDelegate>
#include <QPainter>
#include <QToolTip>

class ElideDelegate : public QStyledItemDelegate
{

public:
    using QStyledItemDelegate::QStyledItemDelegate;

    void paint(QPainter *painter,
               const QStyleOptionViewItem &option,
               const QModelIndex &index)
    const override
    {
        QStyleOptionViewItem opt = option;
        initStyleOption(&opt, index);

        // 获取文本并省略
        const QString text = opt.text;
        QFontMetrics fm(painter->font());
        opt.text = fm.elidedText(text, Qt::ElideRight, opt.rect.width());

        // 绘制默认样式（包括选中状态）
        QStyledItemDelegate::paint(painter, opt, index);
    }

    // 可选：设置工具提示
    bool helpEvent(QHelpEvent *event,
                   QAbstractItemView *view,
                   const QStyleOptionViewItem &option,
                   const QModelIndex &index)
    override
    {
        if (event->type() == QEvent::ToolTip)
        {
            QString text = index.data(Qt::DisplayRole).toString();
            QToolTip::showText(event->globalPos(), text, view);
            return true;
        }
        return QStyledItemDelegate::helpEvent(event, view, option, index);
    }
};

namespace Ui {
class Yb_log_browse;
}

class Yb_log_browse : public QWidget
{
    Q_OBJECT

public:
    explicit Yb_log_browse(QWidget *parent = nullptr);
    ~Yb_log_browse();

    void closeEvent(QCloseEvent *event);

    void populateTree(QTreeWidgetItem *parent, const QJsonValue &value);

signals:

    void destroyW( QString );

private slots:
    void on_pb_exit_clicked();

    void on_pb_require_clicked();

    void on_pb_export_clicked();

    void on_tv_list_clicked(const QModelIndex &index);

    void on_tv_list_doubleClicked(const QModelIndex &index);

private:
    Ui::Yb_log_browse *ui;

    QSqlQuery *qrm, *qro, *qrot;
    QSqlQueryModel *md_list ;//
    QString sq;
    //QSqlQueryModel *md;
    QNetworkRequest request;
    QNetworkAccessManager manager ;

    Pub_pop_delay * dlgDelay;

    QString downloadPath;

    QString cur_busi_code, cur_atinc, cur_in, cur_out;

};

#endif // YB_LOG_BROWSE_H
